package com.funtester.seven.day3;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;

public class JsonT implements Serializable {

    private static final long serialVersionUID = 3599236104065482833L;

    String name;

    int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public JsonT() {
    }

    public JsonT(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public static void main(String[] args) {
        JSONObject json = new JSONObject();
        json.put("23423", 324);
        json.put("233", 23324);
        json.put("233", 324);
        json.put("2", 2324);
        json.put("1", new JsonT("fun", 23));
//        System.out.println(json.get("2"));
//        System.out.println(json.getString("1"));
//        System.out.println(json.getBoolean("233"));
//        System.out.println(json.getBoolean("1"));
        System.out.println(json.getInteger("code"));
        System.out.println(json.getIntValue("code"));//隐藏BUG

        String s = json.toJSONString();//JSON转String
        System.out.println(s);
        JSONObject jsonObject = JSON.parseObject(s);//String转JSON
        System.out.println(jsonObject);
        JsonT nae = new JsonT("nae", 12);
        String s1 = JSON.toJSONString(nae);//序列化,对象到String
        System.out.println(s1);

        JsonT jsonT = JSON.parseObject(s1, JsonT.class);//反序列化,String到对象
        System.out.println(jsonT.name);
        System.out.println(jsonT.age);



    }


}
